﻿using System.Speech.Synthesis;

namespace HY.Common
{
    static class VoiceHelper
    {
        /// <summary>
        /// 语速，-10到10之间，默认0
        /// </summary>
        public static int VoiceRate { get; set; } = 0;
        /// <summary>
        /// 音量，0-100
        /// </summary>
        public static int VoiceVolume { get; set; } = 100;
        public static void PlayVoice(string strVoice)
        {
            SpeechSynthesizer speak = new SpeechSynthesizer();
            speak.Rate = VoiceRate;  //语速
            speak.Volume = VoiceVolume;  //音量
            //同步朗读
            speak.Speak(strVoice);
            speak.SetOutputToNull();
            speak.Dispose();  //释放之前的资源
            //异步朗读
            //speak.SpeakAsync(strVoice);
        }
    }
}
